<?php
/**
 * 带命名空间的Session操作
 *
 * @package SF
 * @author Shuky
 * @since v1.0
 * @version $Id$
 */
namespace SF\Session;

class SessionNS
{
	protected $_namespace = '';

	public function __construct($namespace)
	{
		$this->_namespace = $namespace;
	}

	public function __set($key, $value)
	{
		Session::set($this->_namespace, array_merge($this->_getSession(), array($key => $value)));
	}

	public function __get($key)
	{
		$val = $this->_getSession();
		return isset($val[$key]) ? $val[$key] : null;
	}

	public function __isset($key)
	{
		$val = $this->_getSession();
		return isset($val[$key]);
	}

	public function __unset($key)
	{
		$val = $this->_getSession();
		unset($val[$key]);
		Session::set($this->_namespace, $val);
	}

	public function destroy()
	{
		Session::destroy($this->_namespace);
	}

	protected function _getSession()
	{
		return Session::get($this->_namespace, array());
	}
}